Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ivan Saric 40 posts 89 karma points
    Jul 16, 2014 @ 11:11
    Ivan Saric
    0

    Node Id from app.Context.Items["umbOriginalUrl"]

    Hi, I need to get current node in external project where Node.GetCurrent is not working (null exception). So my idea is to get node id from request URL and I have app.Context.Items["umbOriginalUrl"] which is a same as Node.NiceUrl. My question is how can I get node id from URL? I tried this (below) but node is always null and the urlName from xpath exist in umbraco.content.Instance.XmlContent.

    int GetNodeIdFromUrl(String url)
        {
            Int32 nodeId = -1;
            String xpath = umbraco.requestHandler.CreateXPathQuery(url, false);
    
            if (!String.IsNullOrEmpty(xpath))
            {
                System.Xml.XmlNode node = umbraco.content.Instance.XmlContent.SelectSingleNode(xpath);
                if ((node != null) && (node.Attributes != null))
                {
                    Int32.TryParse(node.Attributes["id"].Value, out nodeId);
                }
            }
    
            return nodeId;
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft